package PriorityQueue;

import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:周次煜
 * Date: 2024-04-13
 * Time：14:32
 */


public class TestPriorityQueue {
    public static void main(String[] args) {
        int[] array={2,4,5,8,9,10,11};
        MyPriorityQueue mpq=new MyPriorityQueue();
        mpq.createHeap(array);
        mpq.push(18);
        mpq.push(19);
        System.out.println("======抛出堆顶元素=======");
        System.out.println(mpq.pollHeap());
        System.out.println(mpq.pollHeap());
        System.out.println("========查看堆顶元素=======");
        System.out.println(mpq.peekHeap());
        System.out.println(mpq.peekHeap());
        System.out.println(mpq.peekHeap());


    }




    public static void main2(String[] args) {
        List<Integer> list=new LinkedList<>();
        list.add(1);
        list.add(2);
        list.add(3);

        PriorityQueue<Integer> prq=new PriorityQueue<>( new ICmp());
//        PriorityQueue<Integer> prq=new PriorityQueue<>( list);
        prq.add(19);
        prq.add(13);
        prq.add(2);
        System.out.println(prq.poll());  // 2
        System.out.println(prq.poll());  // 13
        System.out.println(prq.poll());  // 19
    }


    public static int[] smallestK(int[] arr, int k) {
            PriorityQueue<Integer> prq=new PriorityQueue<>(new ICmp());
            for (int i=0; i < k ;i++) {
                prq.add(arr[i]);
            }

        for (int i = k; i < arr.length; i++) {
            int top= prq.peek();
            if (top >  arr[i]) {
                prq.poll();
                prq.add(arr[i]);
            }
        }

        int []ret=new int[k];
        for (int i = 0; i < k; i++) {
            ret[i]=prq.poll();
        }

        return ret;
    }

    public static void main3(String[] args) {
        int[] array={1,3,5,7,2,4,6,8};
        System.out.println(Arrays.toString(smallestK(array, 4)));
    }
}


class ICmp implements Comparator<Integer> {



    @Override
    public int compare(Integer o1, Integer o2) {
        return o2.compareTo(o1);
    }
}


